package com.ssy.lingxi.product.entity.platform;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.product.entity.material.BaseMaterialProcessDO;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 平台后台 - 物料流程配置
 * @author 彭冬冬
 * @version 2.0.0
 * @date 2022/3/25 9:43
 */
@Entity
@Table(schema = "public",
        name ="product_platform_material_process",
        indexes = {
        @Index(name = "product_platform_material_process_process_type_idx", columnList = "processType"),
        @Index(name = "product_platform_material_process_status_idx", columnList = "status"),
        @Index(name = "product_platform_material_process_create_time_idx", columnList = "createTime")
        }
)
public class PlatformMaterialProcessDO implements Serializable {
    private static final long serialVersionUID = 8098234544603962894L;

    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "product_platform_material_process_seq")
    @SequenceGenerator(sequenceName = "product_platform_material_process_seq", name= "product_platform_material_process_seq", allocationSize = 1)
    private Long id;

    /**
     * 新增、修改时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime createTime;

    /**
     * 流程名称
     */
    @Column(columnDefinition = "varchar(200)")
    private String name;

    /**
     * 流程对应的工作流的key
     */
    @Column(columnDefinition = "varchar(100)")
    private String processKey;

    /**
     * 流程类型，定义在 MaterialProcessTypeEnum 中
     */
    @Column
    private Integer processType;

    /**
     * 状态，来源枚举 MaterialProcessStatusEnum
     */
    @Column
    private Integer status;

    /**
     * 是否适用于所有会员
     */
    @Column
    private Boolean allMembers;

    /**
     * 一对一单向关联物料流程
     */
    @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "base_material_process_id", referencedColumnName = "id")
    private BaseMaterialProcessDO process;

    /**
     * 一对多双向关联适用会员
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "process", cascade = {CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    private List<PlatformMaterialProcessMemberDO> members;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getProcessKey() {
        return processKey;
    }

    public void setProcessKey(String processKey) {
        this.processKey = processKey;
    }

    public Integer getProcessType() {
        return processType;
    }

    public void setProcessType(Integer processType) {
        this.processType = processType;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Boolean getAllMembers() {
        return allMembers;
    }

    public void setAllMembers(Boolean allMembers) {
        this.allMembers = allMembers;
    }

    public BaseMaterialProcessDO getProcess() {
        return process;
    }

    public void setProcess(BaseMaterialProcessDO process) {
        this.process = process;
    }

    public List<PlatformMaterialProcessMemberDO> getMembers() {
        return members;
    }

    public void setMembers(List<PlatformMaterialProcessMemberDO> members) {
        this.members = members;
    }
}
